package com.zhiche.lisa.bms.controller.invoice;

import com.alibaba.fastjson.JSONObject;
import com.zhiche.lisa.bms.BMSApplication;
import com.zhiche.lisa.bms.service.utils.UaaUtil;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.RequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import javax.servlet.Filter;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = BMSApplication.class)
public class InvoiceRegControllerText {
    private MockMvc mockMvc;

    @Autowired
    private WebApplicationContext context;

    private String token;

    @Autowired
    private UaaUtil uaaUtil;

    @Autowired
    private Filter springSecurityFilterChain;
    @Before
    public void setUp() {
        mockMvc = MockMvcBuilders.webAppContextSetup(context).addFilter(springSecurityFilterChain).build();
//        token = uaaUtil.getTenantToken("15110288389");
        token = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJnbXRfY3JlYXRlIjoiMTUzODAzNDMwMTc4MCIsImFjY291bnRJZCI6MTAyLCJ1c2VyX25hbWUiOiIxNTExMDI4ODM4OUAxNjMuY29tIiwic2NvcGUiOlsiYWxsIl0sInJvbGVzIjpbeyJhdXRob3JpdHkiOiJST0xFX0FETUlOIn1dLCJ0ZW5hbnRJZCI6MSwiY29ycE5hbWUiOiLkuK3ogZTnianmtYHvvIjkuK3lm73vvInmnInpmZDlhazlj7giLCJleHAiOjE1MzgwNDE1MDEsImF1dGhvcml0aWVzIjpbIlJPTEVfQURNSU4iXSwianRpIjoiMjY5M2NlZjgtNzVjNS00ODI3LTkzNjYtOGQwOWQyYTlkODkwIiwiY2xpZW50X2lkIjoiZGV2b3BzIiwidXNlcm5hbWUiOiIxNTExMDI4ODM4OUAxNjMuY29tIn0.Ekd5BhL4HneLgzIwIDiOkO0HAM0a4sxnXJRPCJQp_n4";
    }
    @Test
    public void queryInvoiceRegOfNotLackSumText()throws Exception{
        String a = JSONObject.toJSONString(null);
        System.err.println(token);
        RequestBuilder request = MockMvcRequestBuilders.post("/invoiceReg/queryInvoiceRegOfNotLackSum")
                .contentType(MediaType.APPLICATION_JSON).header("Authorization", token).content(a)
                .accept(MediaType.APPLICATION_JSON);
        MvcResult mvcResult = mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk()).andReturn();
        int status = mvcResult.getResponse().getStatus();
        String content = mvcResult.getResponse().getContentAsString();
        System.out.println("返回结果状态：" + status);
        System.out.println(content);
        Assert.assertEquals(status,200);
    }
}
